package com.ycfmedical.bed.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import cn.droidlover.xdroidmvp.log.XLog;

/**
 * 计算时间差工具
 * Created by Administrator on 2017-04-30.
 */

public class CountTime {
    public static String count(String startTime, String EndTime) {
        XLog.e("SJH","开始时间"+startTime+"结束时间"+EndTime);
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
        long diff = 0;
        long hour = 0;
        long min = 0;
        long day = 0;
        try
        {
            Date d1 = df.parse(startTime);
            Date d2 = df.parse(EndTime);
            // long ns = 1000;
            // 获得两个时间的毫秒时间差异
            diff = d1.getTime() - d2.getTime();
            // 计算差多少天
             day = diff / nd;
            // 计算差多少小时
             hour = diff % nd / nh;
            // 计算差多少分钟
             min = diff % nd % nh / nm;
            // 计算差多少秒//输出结果
            // long sec = diff % nd % nh % nm / ns;
            XLog.e("SJH", day + "天" + hour + "小时" + min + "分钟");
        }
        catch (Exception e)
        {
        }
        return Math.abs(hour)+"小时"+Math.abs(min)+"分";
    }

}
